// import 'package:flutter/material.dart';
import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:wowhy/global/state.dart';

import 'login_form_component/state.dart';

class LoginPageState extends GlobalBaseState<LoginPageState> {
  bool submitting;

  GlobalKey<FormBuilderState> formKey;
  TextEditingController usernameController;
  TextEditingController passwordController;

  LoginPageState(
      {this.formKey, this.usernameController, this.passwordController, this.submitting = false});

  @override
  LoginPageState clone() {
    return LoginPageState(
      formKey: this.formKey,
      usernameController: this.usernameController,
      passwordController: this.passwordController,
      submitting: this.submitting,
    );
  }
}

LoginPageState initState(Map<String, dynamic> args) {
  return LoginPageState();
}

class LoginFormConnector extends ConnOp<LoginPageState, LoginFormState> {
  @override
  LoginFormState get(LoginPageState state) {
    return LoginFormState(
      formKey: state.formKey,
      usernameController: state.usernameController,
      passwordController: state.passwordController,
      submitting: state.submitting,
    );
  }

  @override
  void set(LoginPageState state, LoginFormState subState) {
    state.formKey = subState.formKey;
    state.passwordController = subState.passwordController;
    state.usernameController = subState.usernameController;
    state.submitting = subState.submitting;
  }
}
